

from atm.core import accounts
import functools


def user_authentication(func):

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        while True:
            input_account = input("enter your account")
            input_password = input("enter your password")
            user_account = accounts.Account()
            user_account.account = input_account
            try:
                user_account.read()
                if user_account.is_freeze == -1:
                    print("您的账户已被锁定")
                    continue
                if user_account.password == input_password:
                    kwargs["account"] = user_account
                    return func(*args, **kwargs)
                else:
                    print("帐号或密码错误，请重试")
            except FileNotFoundError:
                print("该帐号不存在，请重新数输入")
                continue
            except Exception:
                print("查询失败，请重试")
                continue

    return wrapper
